//package com.pay.wx;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
//import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
//import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
//import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
//import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
//import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
//import org.apache.http.HttpEntity;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpGet;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.client.utils.URIBuilder;
//import org.apache.http.entity.InputStreamEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.util.EntityUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.io.*;
//import java.security.PrivateKey;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
//
//public class WxPayApiV3Utils {
//
//    @Autowired
//    private WXConfig wxPayConfig;
//
//    public String doGet(String url) {
//        try {
////            FileInputStream fileInputStream = new FileInputStream(new File(wxPayConfig.getPrivateKeyPath()));
//            PrivateKey privateKey = PemUtil.loadPrivateKey(wxPayConfig.getPrivateKeyInput());
//            AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
//                    new WechatPay2Credentials(wxPayConfig.getMchID(), new PrivateKeySigner(wxPayConfig.getMchSerialNo(), privateKey)),
//                    wxPayConfig.getV3KEY().getBytes()
//            );
//            CloseableHttpClient httpClient = WechatPayHttpClientBuilder.create()
//                    .withMerchant(wxPayConfig.getMchID(), wxPayConfig.getMchSerialNo(), privateKey)
//                    .withValidator(new WechatPay2Validator(verifier))
//                    .build();
//            URIBuilder uriBuilder = new URIBuilder(url);
////      uriBuilder.setParameter("service_id", "500001");
////      uriBuilder.setParameter("appid", "wxd678efh567hg6787");
////      uriBuilder.setParameter("openid", "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o");
//
//            HttpGet httpGet = new HttpGet(uriBuilder.build());
//            httpGet.addHeader("Accept", "application/json");
//            CloseableHttpResponse response1 = httpClient.execute(httpGet);
////            assertEquals(200, response1.getStatusLine().getStatusCode());
//            HttpEntity entity1 = response1.getEntity();
//            // do something useful with the response body
//            // and ensure it is fully consumed
//            return EntityUtils.toString(entity1);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//
//    public String doPost(String url, String data) {
//        try {
//
//            PrivateKey privateKey = PemUtil.loadPrivateKey(wxPayConfig.getPrivateKeyInput());
//            AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
//                    new WechatPay2Credentials(wxPayConfig.getMchID(), new PrivateKeySigner(wxPayConfig.getMchSerialNo(), privateKey)),
//                    wxPayConfig.getV3KEY().getBytes()
//            );
//            CloseableHttpClient httpClient = WechatPayHttpClientBuilder.create()
//                    .withMerchant(wxPayConfig.getMchID(), wxPayConfig.getMchSerialNo(), privateKey)
//                    .withValidator(new WechatPay2Validator(verifier))
//                    .build();
//            URIBuilder uriBuilder = new URIBuilder(url);
//            HttpPost httpPost = new HttpPost(url);
//            InputStream stream = new ByteArrayInputStream(data.getBytes("utf-8"));
//            InputStreamEntity reqEntity = new InputStreamEntity(stream);
//            reqEntity.setContentType("application/json");
//            httpPost.setEntity(reqEntity);
//            httpPost.addHeader("Accept", "application/json");
//            HttpGet httpGet = new HttpGet(uriBuilder.build());
//            httpGet.addHeader("Accept", "application/json");
//            CloseableHttpResponse response1 = httpClient.execute(httpGet);
////            assertEquals(200, response1.getStatusLine().getStatusCode());
//            HttpEntity entity1 = response1.getEntity();
//            // do something useful with the response body
//            // and ensure it is fully consumed
//            return EntityUtils.toString(entity1);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//}
